package com.bsoft.exchange.controller.queuecall;

import java.sql.SQLException;
import java.util.List;

import com.bsoft.exchange.domain.QueueinformationDomain;
import com.bsoft.exchange.pojo.QueueinformationPojo;
import org.dozer.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.bsoft.exchange.domain.ListQueuesDomain;
import com.bsoft.exchange.pojo.ListQueuesPojo;
import com.bsoft.exchange.response.ResponseEntity;
import com.bsoft.exchange.service.QueuesService;
import com.bsoft.exchange.util.BaseResponse;
import com.bsoft.exchange.util.Constant;


@RestController
@RequestMapping(value = "/queues")
public class QueuesController {

    @Autowired
    QueuesService queuesService;
    @Autowired
    Mapper dozerMapper;

    @RequestMapping(value = "/listQueues",method = RequestMethod.POST,produces = "application/json")
    public ResponseEntity<List<ListQueuesDomain>> listQueues(@RequestBody ListQueuesPojo listQueuesPojo){

        ResponseEntity<List<ListQueuesDomain>> entity=new ResponseEntity<>();
        try {

            BaseResponse<List<ListQueuesDomain>> queuesListResponse = queuesService.listQueues(listQueuesPojo);

            if (queuesListResponse.getCode()==Constant.errorTag){
                entity.setCode(Constant.errorTag);
                entity.setMessage(queuesListResponse.getMessage());
                return entity;
            }

            entity.setCode(Constant.successResponse);
            entity.setMessage("请求成功");
            entity.setData(queuesListResponse.getData());
        } catch (SQLException e) {
            e.printStackTrace();
        }

//        List<listQueuesVo> listQueuesList = new ArrayList();

        return entity;
    }
    @ResponseBody
    @RequestMapping(value = "/getQueueinformation",method = RequestMethod.POST,produces = "application/json")
    public ResponseEntity<QueueinformationDomain>getQueueinformation(@RequestBody QueueinformationPojo data){
        ResponseEntity<QueueinformationDomain> entity=new ResponseEntity<>();
        BaseResponse<QueueinformationDomain> queueinformationDomain= queuesService.getQueueinInfo(
                data.getOrganizationId(),data.getQueuesId());

        entity.setCode(Constant.successResponse);
        entity.setMessage(queueinformationDomain.getMessage());
        entity.setData(queueinformationDomain.getData());
        return entity;
    }
}
